import { FormSchema } from '/@/components/BasicForm/type/form';
import { getComponentLabelList } from '/@/api/system-mgmt/app-mgmt/component';

export const componentSchemas: FormSchema = [
  {
    field: 'name',
    label: '组件名称',
    component: 'Input',
    componentProps: {
      placeHolder: '请输入模块名称',
    },
    labelWidth: 100,
    colProps: { span: 24 },
    required: true,
  },
  {
    field: 'port',
    label: '端口号',
    component: 'Input',
    rules: [
      {
        trigger: 'change',
        required: true,
        message: '请输入端口号',
      },
      {
        trigger: 'change',
        pattern: /^((6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])|[0-5]?\d{0,4})$/g,
        message: '请输入正确的端口号',
      },
    ],
    componentProps: {
      placeHolder: '请输入端口号',
    },
    labelWidth: 100,
    colProps: { span: 24 },
  },
  {
    field: 'label',
    label: '标志',
    component: 'ApiSelect',
    componentProps: () => {
      return {
        api: getComponentLabelList,
        resultField: 'list',
        labelField: 'description',
        valueField: 'value',
        placeHolder: '请选择标志',
      };
    },
    labelWidth: 100,
    colProps: { span: 24 },
    required: true,
  },
  {
    field: 'contextPath',
    label: '访问前缀',
    component: 'Input',
    rules: [
      {
        trigger: 'change',
        required: true,
        message: '请输入访问前缀',
      },
      {
        trigger: 'change',
        pattern: /^\/[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$/,
        message: '以"/"开头, 只包含大小写英文字母或数字或中划线“-”，且不能以中划线“-”开头或结束',
      },
    ],
    componentProps: {
      placeHolder: '请输入微服务访问前缀',
    },
    labelWidth: 100,
    colProps: { span: 24 },
    required: true,
    show: true,
  },
];
